package game.util
{
	import flash.errors.*;
	import flash.events.*;
	import flash.media.*;
	import flash.net.*;
	import flash.utils.*;
	public class MySound
	{
		/** 单列返回对象 */
		private static var _instence:MySound;
		private static var isSing:Boolean=true;
		private var soundAry:Dictionary;
		public function MySound()
		{
			if (isSing)
			{
				throw new IllegalOperationError("单例不能new");
				return;
			}
			
		}
		
		private function init():void{
			soundAry=new Dictionary;
		}
		
		/** 获取声音操作单列类 */
		public static function get instence():MySound
		{
			if (_instence == null)
			{
				isSing=false;
				_instence = new MySound;
				_instence.init();
				isSing=true;
			}
			return _instence;
		}
		/**跑道
		 * 
		 **/
		public function playSound(url:String,b:Boolean=false):void{
			var sound:Sound;
			var soundClass:Class;
			if (url==null || url=="")
			{
				return;
			};
			if (this.soundAry.hasOwnProperty(url))
			{
				sound=soundAry[url];
			}
			else
			{
				try
				{
					soundClass = (getDefinitionByName(url) as Class);
				}
				catch(error:Error)
				{
				};
				if (soundClass == null)
				{
					return;
				};
				sound=Sound(new soundClass);
				//var channel:SoundChannel = new SoundChannel();
				trace(url);
				soundAry[url]=sound;
			};
			
			sound.play();
		}
		
	}
}